package com.jajahome.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by liuhaizhu on 2017/4/27.
 */

public class TimeUtil {
    private final static String TIME_UNIT_DAY = "yyyy年MM月dd日";
    private final static String TIME_UNIT_DAY_SS = "yyyy年MM月dd日 HH:mm:ss";
    private final static String TIME_UNIT_COMMENT = "MM月dd日";
    private final static String NOTICE_TIME = "yyyy-MM-dd";
    private final static String TIME = "dd天HH时mm分ss";


    public static String getTime(long time) {
        Date date = new Date(time * 1000);
        return new SimpleDateFormat(TIME_UNIT_DAY).format(date);
    }

     public static String getDate(long time){
         Date date = new Date(time * 1000);
         return new SimpleDateFormat(TIME_UNIT_DAY).format(date);
     }

    public static String countDown(long time) {
        Date date = new Date(time);
        return new SimpleDateFormat(TIME).format(date);
    }

    public static String getCommentTime(long time) {
        Date date = new Date(time * 1000);
        return new SimpleDateFormat(TIME_UNIT_COMMENT).format(date);
    }

    public static String getTimeDesc(long time) {
        Date date = new Date(time * 1000);
        return new SimpleDateFormat(TIME_UNIT_DAY_SS).format(date);
    }

    public static String getTime(String user_time) {
        String re_time = null;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date d;
        try {
            d = sdf.parse(user_time);
            long l = d.getTime();
            String str = String.valueOf(l);
            // re_time = str.substring(0, 10);
            re_time = str;
        } catch (ParseException e) {
            // TODO Auto-generated catch block e.printStackTrace();
        }
        return re_time;
    }

    public static String getHMS(Long times_remain) {
        int day = 0;
        int hour = 0;
        int minute = 0;
        int second = 0;
        second = times_remain.intValue();
        if (second > 60) {
            minute = second / 60;         //取整
            second = second % 60;         //取余
        }

        if (minute > 60) {
            hour = minute / 60;
            minute = minute % 60;
        }

        if (hour > 24) {
            day = hour / 24;
            hour = hour % 24;
        }
        String secondFormat = second < 10 ? "0" + String.valueOf(second) : "" + second;
        String minuteFormat = minute < 10 ? "0" + String.valueOf(minute) : "" + minute;
        String hourFormat = hour < 10 ? "0" + String.valueOf(hour) : "" + hour;
        String dayFormat = hour < 10 ? String.valueOf(day) : "" + day;

        if (day > 0) {
            return dayFormat + "天";
        } else {
            return hourFormat + "时" + minuteFormat + "分" + secondFormat + "秒";
        }
    }
}
